package com.axl.myapplication3;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;



public class MainActivity extends AppCompatActivity {

    public void setCheckedCallback(int viewId)
    {
        Button btn = findViewById(viewId);
        // 点击事件:
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btn.setText("√");
            }
        });

    }

    /**
     * 在总容器中建一个标签
     *
     * @param text_content 文本
     *
     */
    public void addItemInScreen(String text_content){
        // 取总容器:
        LinearLayout topContainer = findViewById(R.id.topContainer);
        if(topContainer!=null)
        {
            // 添加行容器
            LinearLayout horizontaoContainer = new LinearLayout(this);
            topContainer.addView(horizontaoContainer);// 加入到父节点
            // 行容器属性:
            horizontaoContainer.setOrientation(LinearLayout.HORIZONTAL);// setOrientation("horizontal");
            LinearLayout.LayoutParams layout_for_horizontal = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT
            );
            horizontaoContainer.setLayoutParams(layout_for_horizontal);
            // 文本标签:
            TextView textView = new TextView(this);
            textView.setText(text_content);
            ViewGroup.LayoutParams params_for_text =textView.getLayoutParams();//
            textView.setLayoutParams(new ViewGroup.LayoutParams(
                    400,90
            ));
            //params_for_text.width = 200;
            //params_for_text.height = 45;
            //params_for_text.width = R.dimen.textview_height;

//            textView.setWidth(R.dimen.textview_width);
//            textView.setHeight(R.dimen.textview_height);
            textView.setTextSize(20);
            horizontaoContainer.addView(textView);// 加入到父节点
            // 按钮
            Button button = new Button(this);
            horizontaoContainer.addView(button);// 加入到父节点
            button.setText("?");

            // 点击事件:
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    button.setText("√√√");
                }
            });

//            // 文本标签2:
//            TextView textView2 = new TextView(this);
//            textView2.setText(text_content);
////            textView2.setWidth(R.dimen.textview_width);
////            textView2.setHeight(R.dimen.textview_height);
//            textView2.setTextSize(20);
//            topContainer.addView(textView2);// 加入到父节点

        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
//        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
//            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
//            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
//            return insets;
//        });

//        TextView tv_one = findViewById(R.id.tv_one);
//        tv_one.setText("想学");
//        tv_one.setTextColor(ColorStateList(1,1,1,1));

//        Button btn = findViewById(R.id.btn_0);
//        // 点击事件:
//        btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                btn.setText("#######");
//            }
//        });
//
//        Button btn1 = findViewById(R.id.btn_1);
//        // 点击事件:
//        btn1.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                btn1.setText("#######");
//            }
//        });

//        setCheckedCallback(R.id.btn_0);
//        setCheckedCallback(R.id.btn_1);
//        setCheckedCallback(R.id.btn_2);
//        setCheckedCallback(R.id.btn_3);
//        setCheckedCallback(R.id.btn_4);
//        setCheckedCallback(R.id.btn_5);
//        setCheckedCallback(R.id.btn_6);
//        setCheckedCallback(R.id.btn_7);
//        setCheckedCallback(R.id.btn_8);
//        setCheckedCallback(R.id.btn_9);
//        setCheckedCallback(R.id.btn_10);

//        TextView textView = new TextView(this);
//        textView.setText("这是一个自动创建的文本标签");
//        textView.setTextSize(20);
//
//        // 将TextView添加到布局中
//        LinearLayout layout = findViewById(R.id.autoGenerate); // 替换为您的LinearLayout ID
//        if (layout != null) {
//            layout.addView(textView);
//            TextView textView2 = new TextView(this);
//            textView2.setText("这是一个自动创建的文本标签");
//            textView2.setTextSize(20);
//            layout.addView(textView2);
//
//        }

        addItemInScreen("冥想");
        addItemInScreen("烤膝盖");
        addItemInScreen("健身");
        addItemInScreen("读英语");
        addItemInScreen("收衣服");
        addItemInScreen("米哈游签到");
        addItemInScreen("刷原神");
        addItemInScreen("刷星铁");
        addItemInScreen("刷ZZZ");
        addItemInScreen("刷Bitburner");
        addItemInScreen("刷P5R");
        addItemInScreen("晚上早点睡");

    }

}